home *** CD-ROM | disk | FTP | other *** search
- u
- S T A T E C A P I T A L S
-
- Program by Kenneth Barsky
- Text by Dave Moorman
-
-
- Ken is back with one of his great
- quiz programs. There's nothing to it
- -- just type in the name of the
- Capital City for the displayed State.
- Ken has also included a list of facts
- to which you might want to pay
- attention.
-
- One great feature of this and
- other Barsky Quizes is that mistakes
- are not fatal. The State is just
- shuffled into the stack and will come
- up again. And again. Sooner or later,
- you will certainly get it right!
-
- [NOTE:] Beta Tester Robin Harbron from
- Thunder Bay, Ontario asks, "What
- percentage of subscribers are non-USA?
- This program assumes a us audience.
- 'Your' State (Provence) Capitals are
- completely different in Canada or
- Australia."
-
- Right you are! So, we need Print Shop
- graphics of Canadian, Australian,
- German, Italian, and Romanian
- States/Provences/Districs, along with
- similar information. We can put it
- into Ken's data file and stump us
- parochial USAns. Weans?
-
-
- TECH NOTES
-
- When I first saw this quiz, I
- thought it used a bitmap graphics
- screen with Scripter to print the
- text. But no -- this program uses the
- bottom of the font (the reverse
- characters) to display the state maps
- -- which are Print Shop graphics.
-
- I did a little tweaking to the
- program. I noted that the randomizing
- code was rather archaic.
-
- 96 z=int(rnd(1)*50)+1
- 97 if s$(z)=""then 96
-
- After a state capital is correctly
- identified, s$(z) is made null. On the
- face of it, this is a fair way to grab
- random items -- just once each.
- However, as the quiz progresses, the
- time needed to find an active state
- grows longer. When just one state is
- left, the program -- grabbing random
- items -- could miss an indefinite
- number of times.
-
- A better way is to create an index
- then shuffle it with a FOR-NEXT loop:
-
- dim i(50):for x=1to50:i(x)=x:next
-
- (index created and loaded)
-
- forx=1to50:r=int(rnd(1)*50)+1
-
- (get a random number in R)
-
- i=i(x):i(x)=i(r):i(r)=i:next
-
- (then swap I(X) with I(R) using I)
-
-
- THERE! Done. Count through I(X), and
- each number will come up once,
- randomly.
-
- When a state's capital is not
- correctly named, I added a little
- random shuffle:
-
- r=int(rnd(1)*(t-1))+1:i=i(r):
- i(r)=i(t):i(t)=i
-
- This way, only states still not used
- (1 through T-1) are swapped with I(T).
-
-
- The next problem I found was that
- the program ran out of memory. Ken
- used the servicable technique of
- pulling down the Top of Basic in order
- to have a place for the custom font:
-
- poke56,56:pO55,0:clr
-
- Again, nothing wrong with this --
- until ten strings of data for 50
- states are loaded into arrays.
- The program was short and ran just
- fine -- until I began to fool with it!
-
- A better method for using custom
- fonts is to move UP the Bottom of
- Basic. This requires a boot program.
- We almost always have a boot program
- anyway, so this was no big deal.
-
- First, grab the title screen we
- usually use. Often, these are lines
- 41000 - 41999. Change the title and
- author. Then build the rest of the
- program:
-
- 10 gosub41000
- 20 d = peek(186):ifd<8thend=8
- 30 a$="state capitals"
- 40 ?"<hm><blk><dn><dn><dn>loada$,d"
- 50 ?"<dn><dn><dn><dn>run<hm>
- 60 poke198,2:poke631,13:poke632,13
-
- This is fairly standard "dynamic
- keyboard" work. The LOAD and RUN
- commands are printed on the screen (in
- black, so they are invisible) in such
- a way that two RETURNS will execute
- the commands. Locations 631 and 632
- are poked with 13's (RETURNS), and 198
- is poked with 2. Nothing will happen
- until the program ENDs.
-
- Now for pushing up the Bottom of
- Basic:
-
- 70 q=16:pO44,q:pOq*256,0
-
- I use Q to set the page where Basic
- will begin. Normally, Basic starts at
- 2049 -- page 8, byte 1. We want to put
- the font at 2048, so we are moving
- Basic up to 4097 (page 16, byte 1).
- Location 43 holds the byte byte (1),
- so no reason to fool with it. Just
- poke 44 with q. Also, the byte just
- before the bottom of Basic MUST be 0.
- so we poke q*256 with 0.
-
- That's all there is to it. If you
- want to Bload files, you can do that
- also in the boot program. Once you
- have changed the Bottom of Basic, you
- can continue to do most anything
- except a GOTO or GOSUB.
-
- When the program reaches the end,
- the two RETURNs are executed, LOADing
- the program, and RUNning it.
-
- Now here is the important part.
- Once the program is loaded to the
- raised Bottom of Basic, you don't have
- to worry about it. You can edit and
- save it all day long (unless you reset
- or shut-down). And now some 25000
- bytes of Basic memory are free for
- program and string manipulation.
-
- The font is now at 2048 (page 16),
- and to enable it, POKE 53272,18.
-
- NOTE: The boot was changed to load
- and run the linked and packed version
- of this program. That's a whole other
- story.
-
-
- These are not the Absolute Ways of
- programming. They are just little
- tricks to make the program run better
- and the output cleaner. Ken writes a
- good program. Everything is in logical
- sections. So doing a little tweaking
- is just a fun part of my job. On the
- other hand, some of these tricks might
- be just what you need to get your
- program to look and act exactly the
- way you want it to.
-
- I had to link and pack "state
- caps.pkd" to have more of room on this
- side of the 1541. However, if you want
- to take a look, press <STOP-RESTORE>
- and list the program. Most of my stuff
- is from 20000 and on.
-
- DMM
-
-
-